package design.patterns.decorator.order;

import java.text.NumberFormat;

/**
 * @Desc: OrderLine是一个销售单的货物清单中的一行, 它包括下面的这些信息:产品名、数目、单价、小计金额
 * @author: cww
 * @DateTime: 2020/6/10 11:07
 */

public class OrderLine {

    private String itemName;
    private int units;
    private double unitPrice;


    public double getSubtotal() {
        return unitPrice * units;
    }

    public String getItemName() {
        return itemName;
    }

    public void setItemName(String itemName) {
        this.itemName = itemName;
    }

    public int getUnits() {
        return units;
    }

    public void setUnits(int units) {
        this.units = units;
    }

    public double getUnitPrice() {
        return unitPrice;
    }

    public void setUnitPrice(double unitPrice) {
        this.unitPrice = unitPrice;
    }

    public void printLine(){
        System.out.println(itemName + "\t" + units
                + "\t" + formatCurrency(unitPrice)
                + "\t" + formatCurrency(getSubtotal()));
    }
    private String formatCurrency(double amnt)
    {
        return NumberFormat.getCurrencyInstance().format(amnt);
    }
}
